﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RAMED
{
    public partial class modifeirborderaeuForm : Form
    {
        private Bordereau bord= new Bordereau();
        public Bordereau Bord 
        {
            get { return bord; }
            set { bord = value; }


        }
        public RecherchebordereauForm recherbor { get; set; }

        public modifeirborderaeuForm()
        {
            InitializeComponent();
            RAMEDEntities1 context = SingletonContext.GetContext();
            comboboxannexebordereau.DataSource = context.Annexe_administratif;
            comboboxannexebordereau.DisplayMember = "nom_annexe_administratif";
            comboboxannexebordereau.ValueMember = "id_annexe_administratif";
        }

        private void label2_Click(object sender, EventArgs e)
        {
           
        }

        

       

        private void btnEnregistrer_Click(object sender, EventArgs e)
        {
            RAMEDEntities1 context = SingletonContext.GetContext();
            Bordereau bord = new Bordereau();

            bord = context.Bordereaux.Where(d => d.id_bordereau == Bord.id_bordereau).First();

            bord.type_bordereau = txttypebordereau.Text;
            bord.Nombre_de_carte = utitlitaire.CasterString(txtnombrecarte.Text);
            Annexe_administratif annexe = new Annexe_administratif();
            annexe = (Annexe_administratif)comboboxannexebordereau.SelectedItem;
            bord.Annexe_administratif = annexe;
            recherbor.mettreAjouterFormGridViewbor();
            context.SaveChanges();
            this.Dispose();
        }

        //private void mettreAjouterFormGridView()
        //{
        //    throw new NotImplementedException();
        //}
        public void InitialiserChamps()
        {


            txtnombrecarte.Text = bord.Nombre_de_carte.ToString();
            txttypebordereau.Text = bord.type_bordereau;
            comboboxannexebordereau.SelectedValue = bord.id_annexe_administratif;
            remplirDataGridView();

        }

        private void modifeirborderaeuForm_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void Button21_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void ajouterCarteButton_Click(object sender, EventArgs e)
        {
            AjouterCarteModifierBordereau acmbf = new AjouterCarteModifierBordereau();
            acmbf.modifeirborderaeuForm = this;
            acmbf.Show();
        }
        public void mettreAjourFormGridView()
        {
            dataGridViewbor.DataSource = null;
            remplirDataGridView();
            dataGridViewbor.Update();
            dataGridViewbor.Refresh();
        }

        

        private void remplirDataGridView()
        {
            dataGridViewbor.AutoGenerateColumns = false;
            dataGridViewbor.ColumnCount = 5;
            dataGridViewbor.Columns[0].HeaderText = "Nom";
            dataGridViewbor.Columns[0].DataPropertyName = "Nom_benefi";

            dataGridViewbor.Columns[1].HeaderText = "Prénom";
            dataGridViewbor.Columns[1].DataPropertyName = "Prenom_benefi";

            dataGridViewbor.Columns[2].HeaderText = "IPCM";
            dataGridViewbor.Columns[2].DataPropertyName = "IPCM";

            dataGridViewbor.Columns[3].HeaderText = "CIN";
            dataGridViewbor.Columns[3].DataPropertyName = "CIN_benefi";



            dataGridViewbor.Columns[4].HeaderText = "Centre de santé";
            dataGridViewbor.Columns[4].DataPropertyName = "Centre_sante";


            dataGridViewbor.DataSource = bord.Cartes;
        }

        private void modifierButton_Click(object sender, EventArgs e)
        {
            ModifierCarte modifierCarte = new ModifierCarte();
            RAMEDEntities1 context = SingletonContext.GetContext();
            Carte carte  = ((Carte)dataGridViewbor.CurrentRow.DataBoundItem);

            modifierCarte.Carte = carte; 
            modifierCarte.InitialiserChamps();
            modifierCarte.modifierBordereauForm = this;
            modifierCarte.Show();
        }

        private void dataGridViewbor_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

    }
}
